Skip to content

Simplify Prometheus metric collection#5368

Closed
09Catho wants to merge 1 commit into
open-telemetry:mainfrom
09Catho:fix/prometheus-reader-snapshot
Closed

Simplify Prometheus metric collection#5368
09Catho wants to merge 1 commit into
open-telemetry:mainfrom
09Catho:fix/prometheus-reader-snapshot

Conversation

@09Catho

@09Catho 09Catho commented Jun 29, 2026

Copy link
Copy Markdown

Summary

  • replace the Prometheus collector's metrics deque with a single current metrics snapshot
  • translate the collected snapshot directly during Prometheus collection
  • keep target_info generation and repeated scrape behavior unchanged

Fixes #2500.

Testing

  • PYTHONPATH='I:\OSC\repos\opentelemetry-python\exporter\opentelemetry-exporter-prometheus\src;I:\OSC\repos\opentelemetry-python\opentelemetry-sdk\src;I:\OSC\repos\opentelemetry-python\opentelemetry-api\src;I:\OSC\repos\opentelemetry-python\tests\opentelemetry-test-utils\src' python -m pytest exporter\opentelemetry-exporter-prometheus\tests\test_prometheus_exporter.py -q
  • python -m ruff check exporter\opentelemetry-exporter-prometheus\src\opentelemetry\exporter\prometheus_init_.py exporter\opentelemetry-exporter-prometheus\tests\test_prometheus_exporter.py

Note: I also ran test_entrypoints.py with local PYTHONPATH; the entrypoint import test failed because the package entry point is not installed in this ad hoc environment, while the other 3 tests passed.

Signed-off-by: 09Catho <ashketchume45@gmail.com>
@09Catho 09Catho requested a review from a team as a code owner June 29, 2026 12:43
Copilot AI review requested due to automatic review settings June 29, 2026 12:43
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Prometheus exporter’s collection pipeline by replacing the internal queued MetricsData buffering with a single “current snapshot”, and translating that snapshot directly during Prometheus collect().

Changes:

  • Replace _CustomCollector’s deque of pending MetricsData with a single _metrics_data snapshot.
  • Simplify collect() to translate a single snapshot and yield once per scrape.
  • Preserve cached target_info creation behavior (created once and reused).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +337 to +338
if self._metrics_data is None:
return
@herin049

herin049 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closing this PR as already addressed by #5123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

simplify flow of prometheus metric reader

3 participants